const path = require( 'path' );
const express = require( 'express' );
const morgan = require( 'morgan' );
const nunjucks = require( 'nunjucks' );

const session = require('express-session');

const customerRouter = require( './routes/customer' );

const port = 8080 ;
const application = express();

let options = {
    name: 'KFMID',
    secret: 'kaifamiao',
    resave: false,
    saveUninitialized: true,
    cookie: { secure: false , path: '/' }
}
let sessionMiddleware= session( options );
router.use( sessionMiddleware );

application.use( morgan( 'dev' ) );

application.use( express.json() );
application.use( express.urlencoded( {extended: false } ));
application.use( express.text() );

application.use( express.static( 'assets' ) );

const templateRoot = 'templates' ;

application.set( 'view engine' , 'njk' );
application.set( 'views' , path.resolve( __dirname , templateRoot ) );

nunjucks.configure( templateRoot , { autoescape: true , express: application } );

application.use( '/customer' , customerRouter );

application.listen( port );